<?php
namespace App\Wen\Utils;

//use Facebook\WebDriver\Remote\DesiredCapabilities;
//use Facebook\WebDriver\Remote\RemoteWebDriver;
use Illuminate\Support\Facades\Http;

class BotUtils{
    public static function get_selenium_page($url, $wait = 0){
        if(_empty_($url)){
            return '';
        }
//        $driver = RemoteWebDriver::create(env('SELENIUM_DRIVER_URL'), DesiredCapabilities::chrome());
//
//        if(_empty_($wait)){
//            $scource = $driver->get($url)->getPageSource();
//        }else{
//            $scource = $driver->get($url)->wait(3)->getPageSource();
//        }
//
//        $driver->quit();
        $r = Http::get($url);
        if($r->successful()){
            return $r->body();
        }
        return '';
    }

    public static function get_batch_js_page($urls){
        if(_empty_($urls)){
            return null;
        }
        $results = Http::timeout(1000)->asForm()->post('https://minisns.cn/wp-content/module/public/page/LightsnsRobotByShaowenV4/browser.php?urls={ ‘https://www.baidu.com’ }', ['urls'=>$urls]);
        if($results->successful()){
            $res_ = $results->json();
            if($res_['code'] == 1){
                return $res_['data'];
            }
        }
        _logger_(__file__, __line__, $results->body());
        return null;
    }

    static function remove_html_annotation($content){
        return preg_replace("/<!--(.|\s)*?-->/", "", $content);
    }

}
